using System;
using System.Collections;
using System.Runtime.CompilerServices;
using Awaiter;
using Nsb.Classes;
using jQueryApi;

namespace Yoshi.Classes
{
    [IgnoreNamespace]
    public class ProfileTruple : Truple
    {
        [AlternateSignature]
        public extern Truple PlayAlias();

        public Truple PlayAlias(Dictionary options)
        {
            bool validate = options == null || options["Validate"] == null || (bool)options["Validate"];
            Truple alias = Input("alias").SubHtml(".Label", "Your Play Alias <span style='font-size:70%'>(Required)</span>");
            alias.InputElement().Blur(delegate(jQueryEvent e) { PlayAliasValidate(e, validate); });
            if (options != null)
                alias.SetOptions(options);
            return alias;
        }

        public bool PlayAliasValidate(jQueryEvent e, bool validate)
        {
            string ie = Truples["alias"].InputElement().Plugin<Jewl>().GetFValueString();
            if (validate && (String.IsNullOrEmpty(ie) || ie.Length < 5))
            {
                CancelEvent(e);
                new Await()
                    .AddAw(new Ask().OkAw, "Play Alias with 5 or more characters is required")
                    .AddDx(delegate { Truples["alias"].InputElement().Focus().Click(); })
                    .Commit();
                return false;
            }
            return true;
        }
    }
}